#include <allegro.h>
int main() {
BITMAP *Buffer;
BITMAP *Background;
BITMAP *Image1;
BITMAP *Image2;
BITMAP *Image3;
BITMAP *Background2;
BITMAP *Background3;
BITMAP *GO;


int x1=205;
int y1=300;
int x11=595;
int y11=355;

int x2=205;
int y2=397;
int x22=595;
int y22=447;

int x3=205;
int y3=494;
int x33=595;
int y33=544;
int i=0;
int j=0;

/* General initialization function */
allegro_init();
if (install_keyboard() == -1) {
allegro_message("Error! %s", allegro_error);
return -1;
}
set_color_depth(16);
if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0) != 0) {
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); /* here’s the command for text mode */
allegro_message("Unable to initialize video mode!\n%s\n", allegro_error);
return 1;
}

install_mouse() ;
if (install_mouse () == -1)
{
allegro_message("Erreur ! %s", allegro_error) ;
return -1 ;
}


Buffer = create_bitmap(800, 600);
Background = load_bitmap("a.bmp", NULL);
Image1 = load_bitmap("curseur.bmp" , NULL);
Image2 = load_bitmap("false.bmp" , NULL);
Image3 = load_bitmap("true.bmp" , NULL);
Background2 = load_bitmap("b.bmp", NULL);
Background3 = load_bitmap("c.bmp", NULL);
GO = load_bitmap("game-over.bmp" , NULL);

	if (Background == NULL && Image1 == NULL && Image2 == NULL && Image3 == NULL) 
	{
		allegro_message("could not load images");
		allegro_exit();
	}


while(!key[KEY_ESC] )
{

   blit(Background, Buffer, 0, 0, 0, 0, Background->w, Background->h);
   draw_sprite(Buffer, Background, 0 , 0);
   draw_sprite(Buffer, Image1, mouse_x , mouse_y );
   blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

	if (mouse_x < x11 && mouse_x > x1 && mouse_y < y11 && mouse_y > y1 && (mouse_b & 1))
	{
		draw_sprite(Buffer, Image3, 250, 250);
		blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		i=1;
	}


	if (mouse_x < x22 && mouse_x > x2 && mouse_y < y22 && mouse_y > y2 && (mouse_b & 1))
	{
		draw_sprite(Buffer, Image2, 250, 250);
		blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		i=1;
		j++;
	}

	if (mouse_x < x33 && mouse_x > x3 && mouse_y < y33 && mouse_y > y3 && (mouse_b & 1))
	{
		draw_sprite(Buffer, Image2, 250, 250);
		blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		i=1;
		j++;
	}

				if ((i==1))
				{
				Background=Background2;
				usleep(80000);
				//blit(Background, Buffer, 0, 0, 0, 0, Background->w, Background->h);
				blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
				
				}
	
	if (mouse_x < x11 && mouse_x > x1 && mouse_y < y11 && mouse_y > y1 && (mouse_b & 1))
	{
		draw_sprite(Buffer, Image3, 250, 250);
		blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		i=2;j++;
	}

	if (mouse_x < x22 && mouse_x > x2 && mouse_y < y22 && mouse_y > y2 && (mouse_b & 1))
	{
		draw_sprite(Buffer, Image2, 250, 250);
		blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		i=2;
	}

	if (mouse_x < x33 && mouse_x > x3 && mouse_y < y33 && mouse_y > y3 && (mouse_b & 1))
	{
		draw_sprite(Buffer, Image2, 250, 250);
		blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		i=2;j++;
	}
	

				if ((i==2))
				{
				Background=Background3;
				blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
				usleep(70000);
				}	

	if (mouse_x < x11 && mouse_x > x1 && mouse_y < y11 && mouse_y > y1 && (mouse_b & 1))
	{
		draw_sprite(Buffer, Image3, 250, 250);
		blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		i=3;
	}

	if (mouse_x < x22 && mouse_x > x2 && mouse_y < y22 && mouse_y > y2 && (mouse_b & 1))
	{
		draw_sprite(Buffer, Image2, 250, 250);
		blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		i=3;j++;
	}

	if (mouse_x < x33 && mouse_x > x3 && mouse_y < y33 && mouse_y > y3 && (mouse_b & 1))
	{
		draw_sprite(Buffer, Image2, 250, 250);
		blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
		i=3;j++;
	}
				if (i==3 || j==2) 
				{draw_sprite(Buffer, GO, 250, 250);} //gameover picture
}

readkey();
//destroy_bitmap(Image1);
destroy_bitmap(Buffer);
return 0;
}
END_OF_MAIN();
